home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blanker / source / blankers / utility.c < prev    next >
C/C++ Source or Header  |  1993-08-15  |  6KB  |  222 lines

  1. /*
  2.  *    Copyright (c) 1993 Michael D. Bayne.
  3.  *    All rights reserved.
  4.  *
  5.  *    Please see the documentation accompanying the distribution for distribution and disclaimer information.
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/memory.h>
  10.  
  11. #include <dos/dos.h>
  12.  
  13. #include <intuition/intuition.h>
  14. #include <intuition/screens.h>
  15. #include <intuition/intuitionbase.h>
  16.  
  17. #include <graphics/gfxbase.h>
  18. #include <graphics/gfxmacros.h>
  19. #include <graphics/copper.h>
  20. #include <graphics/videocontrol.h>
  21.  
  22. #include <hardware/custom.h>
  23.  
  24. #include <clib/exec_protos.h>
  25. #include <clib/intuition_protos.h>
  26. #include <clib/graphics_protos.h>
  27. #include <clib/dos_protos.h>
  28.  
  29. extern    struct    IntuitionBase    *IntuitionBase;
  30. __far    extern    struct    Custom    custom;
  31. extern    struct    GfxBase        *GfxBase;
  32.     struct    BitMap        *newMap;
  33.     ULONG            FRandSeed;
  34.  
  35. VOID setCopperList( ULONG height, ULONG color, struct ViewPort *vp )
  36. {
  37.     #define NUMCOLORS 45
  38.  
  39.     struct    UCopList    *uCopList;
  40.     struct    TagItem    uCopTags[] = { { VTAG_USERCLIP_SET, 0L }, { VTAG_END_CM, 0L } };
  41.     register    USHORT    i, index = VBeamPos()%NUMCOLORS, spc;
  42.         UWORD    spectrum[] = {  0x0F00, 0x0E10, 0x0D20, 0x0C30, 0x0B40, 0x0A50, 0x0960, 0x0870, 0x0780, 0x0690,
  43.                 0x05A0, 0x04B0, 0x03C0, 0x02D0, 0x01E0, 0x00F0, 0x00E1, 0x00D2, 0x00C3, 0x00B4,
  44.                 0x00A5, 0x0096, 0x0087, 0x0078, 0x0069, 0x005A, 0x004B, 0x003C, 0x002D, 0x001E,
  45.                 0x000F, 0x010E, 0x020D, 0x030C, 0x040B, 0x050A, 0x0609, 0x0708, 0x0807, 0x0906,
  46.                 0x0A05, 0x0B04, 0x0C03, 0x0D02, 0x0E01 };
  47.     
  48.     if( uCopList = ( struct UCopList * )AllocMem( sizeof( struct UCopList ), MEMF_PUBLIC|MEMF_CLEAR )) {
  49.  
  50.         spc = height/NUMCOLORS;
  51.  
  52.         CINIT( uCopList, NUMCOLORS );
  53.  
  54.         for( i = 0; i<NUMCOLORS; ++i ) {
  55.             CWAIT( uCopList, i*spc, 0 );
  56.             CMOVE( uCopList, custom.color[color], spectrum[(i+index)%NUMCOLORS] );
  57.         }
  58.  
  59.         CEND( uCopList );
  60.  
  61.         Forbid();
  62.         vp->UCopIns = uCopList;
  63.         Permit();
  64.  
  65.         VideoControl( vp->ColorMap, uCopTags );
  66.  
  67.         RethinkDisplay();
  68.     }
  69. }
  70.  
  71. ULONG getTopScreenMode( void )
  72. {
  73.     BPTR lock;
  74.     struct    Screen    *pubScr;
  75.     ULONG scrMode;
  76.  
  77.     lock = LockIBase( 0 );
  78.     pubScr = IntuitionBase->FirstScreen;
  79.     scrMode = GetVPModeID( &(pubScr->ViewPort));
  80.     UnlockIBase( lock );
  81.     return( scrMode );
  82. }
  83.  
  84. ULONG getTopScreenDepth( void )
  85. {
  86.     BPTR lock;
  87.     struct    Screen    *pubScr;
  88.     struct    DrawInfo *dri;
  89.     ULONG sDep = 0;
  90.  
  91.     lock = LockIBase( 0 );
  92.     pubScr = IntuitionBase->FirstScreen;
  93.     if( dri = GetScreenDrawInfo( pubScr )) {
  94.         sDep = dri->dri_Depth;
  95.         FreeScreenDrawInfo( pubScr, dri );
  96.     }
  97.     UnlockIBase( lock );
  98.     return( sDep );
  99. }
  100.  
  101. VOID FreeBitMap37( struct BitMap *bm, LONG Width, LONG Height )
  102. {
  103.     LONG    i;
  104.  
  105.     if( GfxBase->LibNode.lib_Version < 39 ) {
  106.         for( i = 0; i < bm->Depth; i++ ) if( bm->Planes[i] ) FreeRaster( bm->Planes[i], Width, Height );
  107.         FreeVec( bm );
  108.     } else FreeBitMap( bm );
  109. }
  110.  
  111. struct BitMap *AllocBitMap37( ULONG Width, ULONG Height, ULONG Depth, struct Screen *Scr )
  112. {
  113.     struct BitMap    *bm;
  114.     LONG        i;
  115.  
  116.     if( GfxBase->LibNode.lib_Version < 39 ) {
  117.         if( bm = AllocVec( sizeof( struct BitMap ), MEMF_CLEAR|MEMF_PUBLIC )) {
  118.             InitBitMap( bm, Depth, Width, Height );
  119.             for( i = 0; i < Depth; i++ ) if(!( bm->Planes[i] = AllocRaster( Width, Height ))) break;
  120.             if( i == Depth ) return( bm );
  121.             FreeBitMap37( bm, Width, Height );
  122.             return( NULL );
  123.         }
  124.     } else return( AllocBitMap( Width, Height, Depth, BMF_DISPLAYABLE, Scr->RastPort.BitMap ));
  125. }
  126.  
  127. struct Screen *cloneTopScreen( void )
  128. {
  129.     struct    Screen *Scr, *nScr = 0L;
  130.     struct    DrawInfo *dri;
  131.     BPTR    lock;
  132.     ULONG    sMod, sDep, i, Wid, Hei, offx, offy;
  133.     UWORD    *cols;
  134.  
  135.     /* Lock IntuitionBase so nothing goes away while we're playing with it */
  136.     lock = LockIBase( 0 );
  137.  
  138.     /* Grab the first screen and get its attributes */
  139.     Scr = IntuitionBase->FirstScreen;
  140.     sMod = GetVPModeID( &(Scr->ViewPort)); /* Screen Mode ID */
  141.     offx = Scr->LeftEdge; 
  142.     offy = Scr->TopEdge;
  143.     Wid = Scr->Width;
  144.     Hei = Scr->Height;
  145.     if( dri = GetScreenDrawInfo( Scr )) sDep = dri->dri_Depth;
  146.     if( cols = AllocMem( sizeof( WORD ) * ( 1L<<sDep ), MEMF_CLEAR ))
  147.         for( i = 0; i < (1L<<sDep); ++i )
  148.             cols[i] = GetRGB4( Scr->ViewPort.ColorMap, i );
  149.  
  150.     if( newMap = AllocBitMap37( Wid, Hei, sDep, Scr ))
  151.         BltBitMap( Scr->RastPort.BitMap, 0, 0, newMap, 0, 0, Wid, Hei, 0x00C0, 0x00FF, NULL );
  152.  
  153.     UnlockIBase( lock );
  154.  
  155.     if(( newMap )&&( sMod != INVALID_ID )) {
  156.         if( nScr = OpenScreenTags( NULL, SA_Width, Wid, SA_Height, Hei, SA_Depth, sDep, SA_Overscan,
  157.             OSCAN_MAX, SA_DisplayID, sMod, SA_Pens, (ULONG)dri->dri_Pens, SA_Behind, TRUE, SA_BitMap,
  158.             (ULONG)newMap, SA_Quiet, TRUE )) {
  159.             LoadRGB4( &(nScr->ViewPort), cols, 1L << sDep );
  160.             MoveScreen( nScr, offx, offy<0?offy:0 );
  161.             ScreenToFront( nScr );
  162.         }
  163.     }
  164.     if( cols ) FreeMem( cols, ( 1L << sDep ) * sizeof( UWORD ));
  165.     if( dri ) FreeScreenDrawInfo( Scr, dri );
  166.     return( nScr );
  167. }
  168.  
  169. void closeTopScreen( struct Screen *Scr )
  170. {
  171.     ULONG Wid, Hei;
  172.  
  173.     Wid = Scr->Width;
  174.     Hei = Scr->Height;
  175.     CloseScreen( Scr );
  176.     FreeBitMap37( newMap, Wid, Hei );
  177. }
  178.  
  179. ULONG fadeScreen( struct Screen *Screen, ULONG delay )
  180. {
  181.     UWORD    col, i, go = 1;
  182.  
  183.     while( go ) {
  184.         go = 0;
  185.         for( i = 0; i < (1L << Screen->RastPort.BitMap->Depth); ++i ) {
  186.             if( SetSignal( 0L, SIGBREAKF_CTRL_C ) & SIGBREAKF_CTRL_C ) break;
  187.             if( col = GetRGB4( Screen->ViewPort.ColorMap, i )) go = 1;
  188.             SetRGB4( &(Screen->ViewPort), i,
  189.                 ((col & 0x0F00)>>8)?((col & 0x0F00)>>8)-1:0,
  190.                 ((col & 0x00F0)>>4)?((col & 0x00F0)>>4)-1:0,
  191.                 (col & 0x000F)?(col & 0x000F)-1:0 );
  192.         }
  193.         if( i == ( 1L<<Screen->RastPort.BitMap->Depth )) Delay( delay );
  194.         else return( FALSE );
  195.     }
  196.     return( TRUE );
  197. }
  198.  
  199. ULONG FRand( VOID )
  200. {
  201.     return( FRandSeed = ( FRandSeed << 1 )^( 0x1D872B41 ));
  202. }
  203.  
  204.     UWORD    *BlankPtr;
  205. struct    Window    *BlankWnd;
  206.  
  207. VOID BlankMousePointer( VOID )
  208. {
  209.     if( BlankPtr = AllocVec( sizeof( WORD ) * 4, MEMF_CHIP )) {
  210.         if( BlankWnd = OpenWindowTags( 0L, WA_Activate, TRUE, WA_Width, 10, WA_Height, 10, WA_Borderless,
  211.             TRUE, TAG_END )) {
  212.             SetPointer( BlankWnd, BlankPtr, 0, 0, 0, 0 );
  213.         }
  214.     }
  215. }
  216.  
  217. VOID UnblankMousePointer( VOID )
  218. {
  219.     if( BlankWnd ) CloseWindow( BlankWnd );
  220.     if( BlankPtr ) FreeVec( BlankPtr );
  221. }
  222.